<?php

namespace App\Http\Controllers\Mobile;


use App\Logics\AccountLogic;
use App\Logics\EventLogic;
use App\Logics\OrderLogic;
use App\Logics\SiteLogic;
use App\Logics\UserAuthLogic;

class HomeController extends BaseController
{
    // 一般操作
    public function initialize()
    {
        parent::initialize();
    }

    // token
    public function token()
    {
        $logic  = new AccountLogic();
        $result = $logic->token();
        if($result === false){
            return $this->error($logic->getError());
        }

        return $this->success($result);
    }

    // 首页
    public function index()
    {
        // 参数
        $option     = $this->optLogic();
        $proposeNum = $option->getData('propose_number', 4, 'intval');
        $gameNum    = $option->getData('game_number', 5, 'intval');
        $studyNum   = $option->getData('study_number', 5, 'intval');
        $studentNum = $option->getData('student_number', 5, 'intval');

        // 焦点图 广告 first_top_banner
        $adv = (new SiteLogic())->adv('first_top_banner');

        // 通知公告 报名学生
        $option->setField('add_event', 1);
        $student = (new OrderLogic())->getStudent(0, $studentNum);

        // 推荐机构，学校
        $school = (new UserAuthLogic())->getPropose('school', 10, $this->myUid);

        $logic = new EventLogic();
        // 推荐研学，赛事+研学
        $propose = $logic->getPropose($proposeNum);

        // 研学列表：最新
        $game = $logic->getNewest('game', $gameNum);

        // 赛事列表：最新
        $study  = $logic->getNewest('study', $studyNum);
        $result = ['adv' => $adv, 'student' => array_values($student), 'school' => $school, 'propose' => $propose, 'game' => $game, 'study' => $study];

        return $this->success($result);
    }
}


